﻿// controller for the search results by pattern
angular.module('app.search').controller('SearchResultsByPatternController', ['$scope', '$state', 'searchService', 'dataService',
	function ($scope, $state, searchService, dataService) {
		'use strict';
		// initialize the variables
		$scope.pattern = { Name: '', IconUrl: '../transparent' };

		var instance = this;
		// handle the response for the image search
		this.handleGetImagesResponse = function (response) {
			$scope.handleGetImagesResponse(response);
		};
		// call the search service to find the images by pattern
		searchService.byPattern($state.params.tolerance, $state.params.patternId).then(instance.handleGetImagesResponse);
		// download the pattern to diplay the name and icon
		dataService.download('PatternDescription', 'Id = ' + $state.params.patternId.toString()).then(function (response) {
			if (response.data.Successful && response.data.Content.length > 0) {
				// set the pattern
				$scope.pattern = response.data.Content[0];
			}
		});
	}]);